package cn.data.collection.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/***
 * 
 * @ClassName: DateUtils
 * @Description: TODO时间处理工具
 * @author 陈周敏 zmchen@biznest.cn
 * @date 2014年12月4日 下午3:59:44
 *
 */
public class DateUtils {

	public static final String DATETIME_FORMATE = "yyyy-MM-dd HH:mm:ss";
	public static final String DATE_FORMATE = "yyyy-MM-dd";
	public static final String TIME_FORMATE = "HH:mm:ss";

	public static String plusOrMinusDate(int dayNum, String timeZone) {
		Calendar rightNow = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(StringUtil.isRealEmpty(timeZone) ? DATE_FORMATE : timeZone);
		// 得到当前时间，+3天
		// rightNow.add(java.util.Calendar.DAY_OF_MONTH, 3);
		// 如果是后退几天，就写 -天数 例如：
		rightNow.add(java.util.Calendar.DAY_OF_MONTH, dayNum);

		return sdf.format(rightNow.getTime());
	}

	public static String plusDateWithoutWeekend(int dayNum, String timeZone) {

		Calendar rightNow = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(StringUtil.isRealEmpty(timeZone) ? DATE_FORMATE : timeZone);
		// 得到当前时间，+3天
		// rightNow.add(java.util.Calendar.DAY_OF_MONTH, 3);
		// 如果是后退几天，就写 -天数 例如：
		rightNow.add(java.util.Calendar.DAY_OF_MONTH, dayNum);

		// 进行时间转换
		if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
			rightNow.add(java.util.Calendar.DAY_OF_MONTH, -1);
		} else if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
			rightNow.add(java.util.Calendar.DAY_OF_MONTH, -2);
		} else {
//			System.out.println("workDate");
		}

		return sdf.format(rightNow.getTime());
	}

	public static String nowDate(String timeZone) {
		SimpleDateFormat sdf = new SimpleDateFormat(StringUtil.isRealEmpty(timeZone) ? DATE_FORMATE : timeZone);
		return sdf.format(new Date());
	}

	public static void main(String[] args) {
		System.out.println(DateUtils.plusDateWithoutWeekend(-1, DATE_FORMATE));
		System.out.println(100%50);
		System.out.println(DataUtils.MAXSHOULIHAODATA.get("06"));
		System.out.println("08||02||29||21".indexOf("10"));
	}
}
